<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class mdl_hasil_seleksi extends CI_Model {
    
	function __construct(){
        parent::__construct();
    }
	
	function getdata($plimit=true){
		# get parameter from easy grid
		$page = isset($_POST['page']) ? intval($_POST['page']) : 1;  
		$limit = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
		$sort = isset($_POST['sort']) ? strval($_POST['sort']) : 'a.no_pendaftaran';  
		$order = isset($_POST['order']) ? strval($_POST['order']) : 'asc';  
		$offset = ($page-1)*$limit;
		
		# create query
		$this->db->flush_cache();
		$this->db->start_cache();
			$this->db->select('a.id_pendaftaran, a.thn_penerimaan, a.no_pendaftaran, a.nama, b.nama_fakultas, d.nama_prodi, a.status');
			$this->db->from('tbl_pendaftaran a');
			$this->db->join('tbl_fakultas b', 'b.kd_fakultas = a.fakultas1');
			$this->db->join('tbl_fakultas c', 'c.kd_fakultas = a.fakultas2');
			$this->db->join('tbl_prodi d', 'd.kd_prodi = a.prodi1');
			$this->db->join('tbl_prodi e', 'e.kd_prodi = a.prodi2');
			$this->db->order_by($sort, $order);
		$this->db->stop_cache();
		
		# get count
		$tmp['row_count'] = $this->db->get()->num_rows();
		
		# get data
		if($plimit == true){
			$this->db->limit($limit, $offset);
		}
		$tmp['row_data'] = $this->db->get();
		
		return $tmp;
	}
	
	function togrid($data, $count){
		$response->total = $count;
		if($count>0){
			$i=0;
			foreach($data->result_array() as $row){
				foreach($row as $key => $value){
					$response->rows[$i][$key]=$value;
				}
				$i++;
			}
		}
		return json_encode($response);
	}
	
	/*
	function getdataedit($kode){
		$this->db->flush_cache();
		$this->db->select('*');
		$this->db->from('tbl_pendaftaran');
		$this->db->where('id_pendaftaran', $kode);
		
		return $this->db->get();
	}
	
	
	
	function isExistKode($kode){
		if ($kode!=null)
			$this->db->where('id_pendaftaran',$kode);
		
		$this->db->select('*');
		$this->db->from('tbl_pendaftaran');
		$query = $this->db->get();
		
		$rs = $query->num_rows() ;		
		$query->free_result();
		
		return ($rs>0);
	}
	
	function InsertOnDb($data){
		//query insert data		
		$this->db->flush_cache();
		$this->db->set('thn_penerimaan', $data['thn_penerimaan']);
		$this->db->set('no_pendaftaran', $data['no_pendaftaran']);
		$this->db->set('nama', $data['nama']);
		$this->db->set('alamat', $data['alamat']);
		$this->db->set('asal_sekolah', $data['asal_sekolah']);
		$this->db->set('fakultas1', $data['fakultas1']);
		$this->db->set('prodi1', $data['prodi1']);
		$this->db->set('fakultas2', $data['fakultas2']);
		$this->db->set('prodi2', $data['prodi2']);
		$this->db->set('nama_ortu', $data['nama_ortu']);
		$this->db->set('alamat_ortu', $data['alamat_ortu']);
		$this->db->set('pekerjaan', $data['pekerjaan']);
		$this->db->set('status', $data['status']);
		$result = $this->db->insert('tbl_pendaftaran');
		
		//return
		if($result) {
			return TRUE;
		}else {
			return FALSE;
		}
	}
	
	function UpdateOnDb($data){
		//query insert data		
		$this->db->flush_cache();
		$this->db->set('thn_penerimaan', $data['thn_penerimaan']);
		$this->db->set('no_pendaftaran', $data['no_pendaftaran']);
		$this->db->set('nama', $data['nama']);
		$this->db->set('alamat', $data['alamat']);
		$this->db->set('asal_sekolah', $data['asal_sekolah']);
		$this->db->set('fakultas1', $data['fakultas1']);
		$this->db->set('prodi1', $data['prodi1']);
		$this->db->set('fakultas2', $data['fakultas2']);
		$this->db->set('prodi2', $data['prodi2']);
		$this->db->set('nama_ortu', $data['nama_ortu']);
		$this->db->set('alamat_ortu', $data['alamat_ortu']);
		$this->db->set('pekerjaan', $data['pekerjaan']);
		$this->db->set('status', $data['status']);
		$this->db->where('id_pendaftaran', $data['id_pendaftaran']);
		$result = $this->db->update('tbl_pendaftaran');
		
		//return
		if($result) {
			return TRUE;
		}else {
			return FALSE;
		}
	}
	
	function DeleteOnDb($kode){
		$this->db->flush_cache();
		$this->db->where('id_pendaftaran', $kode);
		$result = $this->db->delete('tbl_pendaftaran'); 
		
		if($result) {
			return TRUE;
		}else {
			return FALSE;
		}
	}
	*/
}

?>